package com.wv.api.server.basic;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.util.SaResult;
import com.wv.api.server.common.BaseController;
import com.wv.api.service.basic.IBasicAreaCodeService;
import com.wv.common.result.Result;
import com.wv.model.basic.BasicAreaCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/area")
@Api(tags = "地区编码")
public class BasicAreaCodeController extends BaseController {

    @Autowired
    private IBasicAreaCodeService basicAreaCodeService;

    @GetMapping
    @SaCheckPermission("area:list")
    @ApiOperation("获取树状数据")
    public Result getTreeData() {
        return basicAreaCodeService.getTreeData();
    }

    @GetMapping("/all")
    @SaCheckPermission("area:list")
    @ApiOperation("获取所有地区")
    public Result getAll() {
        return basicAreaCodeService.getAll();
    }

    @PostMapping
    @SaCheckPermission("area:add")
    @ApiOperation("添加地区")
    public SaResult add(@RequestBody BasicAreaCode basicAreaCode) {
        return basicAreaCodeService.addArea(basicAreaCode);
    }

    @PutMapping
    @SaCheckPermission("area:update")
    @ApiOperation("更新地区信息")
    public SaResult update(@RequestBody BasicAreaCode basicAreaCode) {
        return basicAreaCodeService.updateArea(basicAreaCode);
    }

    @DeleteMapping
    @SaCheckPermission("area:delete")
    @ApiOperation("删除地区信息")
    public SaResult delete(String id) {
        return basicAreaCodeService.deleteArea(id);
    }
}
